package org.tea.inventory.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.tea.inventory.dao.tea.LogisticsCompanyMapper;
import org.tea.inventory.domain.sys.UserInfo;
import org.tea.inventory.domain.tea.LogisticsCompany;
import org.tea.inventory.domain.tea.StoreInfo;
import org.tea.inventory.service.ILogisticsCompanyService;
import org.tea.inventory.utils.UserUtil;

import java.util.Date;
import java.util.List;

/**
 * 物流公司信息Service业务层处理
 * 
 * @author dongxb
 * @date 2025-04-14
 */
@Service
public class LogisticsCompanyServiceImpl implements ILogisticsCompanyService
{
    @Autowired
    private LogisticsCompanyMapper logisticsCompanyMapper;

    /**
     * 查询物流公司信息
     * 
     * @param id 物流公司信息主键
     * @return 物流公司信息
     */
    @Override
    public LogisticsCompany selectLogisticsCompanyById(Long id)
    {
        return logisticsCompanyMapper.selectLogisticsCompanyById(id);
    }

    /**
     * 查询物流公司信息列表
     * 
     * @param logisticsCompany 物流公司信息
     * @return 物流公司信息
     */
    @Override
    public List<LogisticsCompany> selectLogisticsCompanyList(LogisticsCompany logisticsCompany)
    {
        logisticsCompany.setDelFlag(0);
        List<LogisticsCompany> list = logisticsCompanyMapper.selectLogisticsCompanyList(logisticsCompany);
        list.stream().forEach(bean -> {
            bean.setStatusStr(bean.getStatus() == 0 ? "启用" : "停用");
        });
        return list;
    }

    /**
     * 新增物流公司信息
     * 
     * @param logisticsCompany 物流公司信息
     * @return 结果
     */
    @Override
    public int insertLogisticsCompany(LogisticsCompany logisticsCompany)
    {
        logisticsCompany.setCreateDate(new Date());
        logisticsCompany.setCreateUserId(UserUtil.getUser().getLoginId());
        return logisticsCompanyMapper.insertLogisticsCompany(logisticsCompany);
    }

    /**
     * 修改物流公司信息
     * 
     * @param logisticsCompany 物流公司信息
     * @return 结果
     */
    @Override
    public int updateLogisticsCompany(LogisticsCompany logisticsCompany)
    {
        logisticsCompany.setUpdateDate(new Date());
        logisticsCompany.setUpdateUserId(UserUtil.getUser().getLoginId());
        return logisticsCompanyMapper.updateLogisticsCompany(logisticsCompany);
    }

    /**
     * 批量删除物流公司
     * 
     * @param ids 需要删除的物流公司信息主键
     * @return 结果
     */
    @Override
    public int deleteLogisticsCompanyByIds(Long[] ids)
    {
        return logisticsCompanyMapper.deleteLogisticsCompanyByIds(ids);
    }

    /**
     * 删除物流公司信息
     * 
     * @param id 物流公司信息主键
     * @return 结果
     */
    @Override
    public int deleteLogisticsCompanyById(Long id)
    {
        LogisticsCompany logisticsCompany = new LogisticsCompany();
        logisticsCompany.setId(id);
        logisticsCompany.setDelFlag(1);
        return logisticsCompanyMapper.updateLogisticsCompany(logisticsCompany);
    }

    /**
     * 更新物流公司状态
     *
     * @param id 物流公司信息主键
     * @param status 物流公司更新前状态
     * @return 结果
     */
    @Override
    public int updateStatus(Long id, Integer status) {
        UserInfo user = UserUtil.getUser();
        LogisticsCompany logisticsCompany = new LogisticsCompany();
        logisticsCompany.setId(id);
        logisticsCompany.setStatus(status == 0 ? 1 : 0);
        logisticsCompany.setUpdateDate(new Date());
        logisticsCompany.setUpdateUserId(user.getLoginId());
        return logisticsCompanyMapper.updateLogisticsCompany(logisticsCompany);
    }
}
